<?php
/**
 * Created by PhpStorm.
 * User: sunlight
 * Date: 2018/11/19
 * Time: 15:08
 */

namespace app\common\model;


class AdminUser extends BaseModel{

    /**
     * 后台自动化分页
     * @param array $data
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getProduct($data=[]){
        $data['status']=[
            'neq', config('code.status_delete')
        ];

        $order = ['id' => 'desc'];

        // 查询
        $result=$this->where($data)->order($order)->paginate();

        //调试
        //echo $this->getLastSql();

        return $result;
    }

    /**
     * 根据条件来获取列表的数据
     * @param array $condition
     * @param int $from
     * @param int $size
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getProductByCondition($condition = [], $from=0, $size = 5){
        if (!isset($condition['status'])){
            $condition['status']=[
                'neq', config('code.status_delete')
            ];
        }

        $order = ['id' => 'desc'];

        $result=$this->where($condition)
            ->limit($from,$size)
            ->order($order)->select();

        //调试
        //echo $this->getLastSql();

        return $result;
    }

    /**
     * 根据条件来获取列表的数据的总数
     * @param array $condition
     * @return int|string
     */
    public function getProductCountByCondition($condition=[]){
        if (!isset($condition['status'])){
            $condition['status']=[
                'neq', config('code.status_delete')
            ];
        }

        return $this->where($condition)->count();

        //echo $this->getLastSql();
    }

}